home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Over 1,000 Windows 95 Programs
/
Over 1000 Windows 95 Programs (Microforum) (Disc 1).iso
/
1249
/
euclid.t
< prev
next >
Wrap
Text File
|
1997-04-18
|
871b
|
56 lines
%
% "euclid.t" finds the greatest common denominator
% of two integers using Euclid's algorithm
%
% Sample program for the T Interpreter by:
%
% Stephen R. Schmitt
% 962 Depot Road
% Boxborough, MA 01719
%
var x, y, z : int
program
put "Numbers must be positive integers!"
prompt "enter numerator:"
get x
assert x > 0
prompt "enter denominator:"
get y
assert y > 0
z := gcd( x, y )
put "greatest common denominator = ", z
put "smallest numerator = ", x/z
put "smallest denominator = ", y/z
end program
function gcd( u : int, v : int ) : int
var t : int
loop
exit when u <= 0
if u < v then
t := u
u := v
v := t
end if
u := u - v
end loop
return v
end function